package src 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	/**
	 * JUST UI and sensative to mouse...
	 * @author Vitaly Vrublevskyy
	 */
	public class Board extends Sprite 
	{
		private var background:Sprite;
		private var container:Sprite;
			
		public function Board() 
		{
			background = drawBackground();
			background.mouseEnabled = false;
			addChild(background);
		}

		
		public function setUp(board:Array):void
		{
			container = new Sprite();
			for (var i:int = 0; i < board.length; i++) 
			{
				for (var j:int = 0; j < board[i].length; j++) 
				{
					var entity:Entity = new Entity(i, j);
					entity.type = board[i][j];
					entity.positioning();
					container.addChild(entity);
				}
			}
			addChild(container);
		}
		
		public function drop(items:Array) 
		{
			for each(var entity:Entity in items) 
			{
				container.removeChild(entity);
				entity = null;
			}	
		}
		
		private function drawBackground():Sprite 
		{
			var sprite:Sprite = new Sprite();
			
			var w:uint = Entity.SIZE;
			var h:uint = Entity.SIZE;
			var bitmapData:BitmapData = new BitmapData( w * 2, h *2, false, Constant.DARK_COLOR);
			var rect1:Rectangle = new Rectangle(0, 0, w, h);
			var rect2:Rectangle = new Rectangle(w, h, w * 2, h * 2);
			var colorTransform:ColorTransform = new ColorTransform();
			colorTransform.alphaMultiplier = 0.5
			bitmapData.colorTransform(rect1, colorTransform)
			bitmapData.colorTransform(rect2, colorTransform)
			
			sprite.graphics.beginBitmapFill(bitmapData, null, true );
			sprite.graphics.drawRect( 0, 0, w * Constant.ROWS , h * Constant.COLUMNS);
			sprite.graphics.endFill();
			
			sprite.alpha = .85;
			return sprite;
		}
		
		

	}

}